package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.user.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userShoppingCateController")
@RequestMapping("user/shoppingCart")
@Slf4j
@Api(tags = "购物车相关接口")
public class ShoppingCartController {

    private final ShoppingCartService shoppingCartService;


    @Autowired
    public ShoppingCartController(ShoppingCartService shoppingCartService) {
        this.shoppingCartService = shoppingCartService;
    }

    /**
     * 添加购物车
     * @param shoppingCartDTO 购物车实体咧DTO
     * @return Result
     */
    @PostMapping("/add")
    @ApiOperation("添加购物车")
    public Result<?> addShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("执行 添加购物车 接口：{}",shoppingCartDTO);
        shoppingCartService.addShoppingCart(shoppingCartDTO);
        return Result.success();
    }

    /**
     * 清空购物车
     * @return Result
     */
    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result<?> cleanShoppingCart(){
        log.info("执行 清空购物车 接口");
        shoppingCartService.cleanShoppingCart();
        return Result.success();
    }


    /**
     * 查看购物车
     * @return 购物车集合
     */
    @GetMapping("/list")
    @ApiOperation("查看购物车")
    public Result<List<ShoppingCart>> listShoppingCart(){
        log.info("执行 查看购物车 接口");
        List<ShoppingCart> shoppingCarts = shoppingCartService.listShoppingCart();
        return Result.success(shoppingCarts);
    }
}
